Understand the structure of Rmarkdown documents
Understanding output formats in Rmarkdown
Understand coding in the Rmarkdown environment
Understand the basic patterns in markdown syntax
Building beautiful documents in Rmarkdown
An Rmarkdown file is a file with a “.Rmd” extension and in Rstudio it looks as below
Rmarkdown Structure
So, in general expect three different pieces in the Rmarkdown file
YAML metadata (- - -) - details the output and some metadata related to the file
Text and Formatting - Text interminced with symbols that help format text in the output document
Code chunks and outputs (```) - Executable R code chunks with output, similar to code cells in jupyter notebook
Rmarkdown structure
Why Rmarkdown??
The YAML header defined by key: value pairs between a pair of - - -
#We write our code here
Chunk output can be customized with knitr options, arguments set in the {} of a chunk header:
volcanic_data = read.csv("city.csv")
head(volcanic_data)
## City.1 City.2 City.3 City.4 City.5
## 1 29 20 23 20 19
## 2 32 24 26 24 24
## 3 36 31 32 29 29
## 4 40 37 38 34 38
## 5 43 40 41 37 43
## 6 37 38 40 36 38
## Warning: package 'knitr' was built under R version 3.4.3
| City.1 | City.2 | City.3 | City.4 | City.5 |
|---|---|---|---|---|
| 29 | 20 | 23 | 20 | 19 |
| 32 | 24 | 26 | 24 | 24 |
| 36 | 31 | 32 | 29 | 29 |
| 40 | 37 | 38 | 34 | 38 |
| 43 | 40 | 41 | 37 | 43 |
| 37 | 38 | 40 | 36 | 38 |
summary(volcanic_data)
## City.1 City.2 City.3 City.4
## Min. :29.00 Min. :20.00 Min. :23.00 Min. :20.00
## 1st Qu.:31.75 1st Qu.:27.00 1st Qu.:29.00 1st Qu.:26.25
## Median :34.50 Median :33.50 Median :34.00 Median :31.00
## Mean :34.58 Mean :31.58 Mean :32.92 Mean :29.75
## 3rd Qu.:37.00 3rd Qu.:37.00 3rd Qu.:37.25 3rd Qu.:33.25
## Max. :43.00 Max. :40.00 Max. :41.00 Max. :37.00
## City.5
## Min. :19.00
## 1st Qu.:27.75
## Median :33.50
## Mean :31.67
## 3rd Qu.:36.50
## Max. :43.00
plot(volcanic_data$City.1, volcanic_data$City.2)
Markdown is a lightweight and easy-to-use syntax for styling and formatting all forms of text.
Think of HTML but much more cleaner and easier to read, even without the output
How does Rstudio understand R and markdown combined together?
This may sound complicated, but R Markdown makes it extremely simple by encapsulating all of the above processing into a single render function.
Using Rmarkdown, we can bold text using Bold and Beautiful or Bold and Beautiful
Now, for italic we have, Smooth and Slant or Smooth and Silent
Combining both in single line Bold and Silent
BLAH BALH BLAH!!!
Essentially, all models are wrong, but some are useful. - George Box
Standard Deviation equation:
Mardown gives us the ability to write math equations using latex, a cheat sheet is available at the following link
The standard deviation is given by the following formula
\[\sigma = \sqrt{\frac{1}{N} \sum_{i=1}^N (x_i - \overline{x})^2}\]
Sigma: \(\sigma\)
Pi: \(\pi\)
Alpha: \(\alpha\)
Lambda: \(\lambda\)
Greater than or equal to: \(\ge\)
Plus or minus: \(\pm\)
Markdown allows us to define headings using the hash symbol
The size of the heading gets smaller when the number of hashes increase
The table of contents are also generated using the number of hash symbols
“#” First level heading
“##” Second level sub heading
“###” Third level sub heading